package com.tracy.lifeproject.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.tracy.lifeproject.R;
import com.tracy.lifeproject.bean.CommodityBean;

import java.util.List;

/**
 * Created by 999555yun on 2016/7/21.
 */
public class CommodityAdapter extends BaseAdapter {
    private Context mContext;
    private List<CommodityBean.DataBean.ItemsBean> mList;

    public CommodityAdapter(Context context ,List<CommodityBean.DataBean.ItemsBean> datas){
        this.mContext = context;
        this.mList = datas;
    }
    @Override
    public int getCount() {
        return mList==null ? 0 : mList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.commodity_item, parent, false);
        TextView tv1 = (TextView) view.findViewById(R.id.text_commodity);
        TextView tv2 = (TextView) view.findViewById(R.id.text_commodity_good);
        TextView tv3 = (TextView) view.findViewById(R.id.text_commodity_price);
        ImageView iv = (ImageView) view.findViewById(R.id.img_commodidy);
        Picasso.with(mContext).load(mList.get(position).getCover_image_url()).into(iv);
        tv1.setText(mList.get(position).getName());
        tv2.setText(Integer.toString(mList.get(position).getFavorites_count()));
        tv3.setText(mList.get(position).getPrice());
        return view;
    }

}
